using System;
using System.Collections.Generic;
using System.Text;

namespace DSP.Library
{
    public class Analys
    {
        public static float Average(float[] arr)
        {
            float ret = 0;
            int count = arr.Length;
            for (int i = 1; i <= count; i++)
            {
                ret += arr[i - 1] / count;
            }
            return ret;
        }

        public static float Disp(float[] arr)
        {
            float ret = 0;
            int count = arr.Length;
            float avg = Average(arr);
            for (int i = 1; i <= count; i++)
            {
                ret += (arr[i - 1] - avg) * (arr[i - 1] - avg) / (count - 1);
            }
            return ret;
        }

        public static float SrKv(float[] arr)
        {
            return (float)Math.Sqrt(Disp(arr));
        }

        public static float Covar(float[] arr)
        {
            return SrKv(arr) / Average(arr);
        }

        public static float KoefAss(float[] arr)
        {
            float ret = 0;
            int count = arr.Length;
            float avg = Average(arr);
            float srkv = SrKv(arr);

            for (int i = 1; i <= count; i++)
            {
                ret += (float)(Math.Pow((arr[i - 1] - avg), 3) / (count * Math.Pow(srkv, 3)));
            }
            return ret;
        }

        public static float KoefEx(float[] arr)
        {
            float ret = 0;
            int count = arr.Length;
            float avg = Average(arr);
            float srkv = SrKv(arr);

            for (int i = 1; i <= count; i++)
            {
                ret += (float)(Math.Pow((arr[i - 1] - avg), 4) / (count * Math.Pow(srkv, 4)));
            }
            return (ret - 3);
        }
    }
}
